package com.infore.dataAudit.util;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.infore.dataAudit.entity.TDataAudit;

public class FilteredTestData {

	static SimpleDateFormat formatter = new SimpleDateFormat("HH");

	public static List<TDataAudit> filter(List<TDataAudit> data, String frequency) {

		List<TDataAudit> newData = new ArrayList<TDataAudit>();

		for (TDataAudit dataAudit : data) {
			if (determine(dataAudit, frequency)) {
				newData.add(dataAudit);
			}
		}

		return data;
	}

	public static boolean determine(TDataAudit dataAudit, String frequency) {
		String time = formatter.format(dataAudit.getCreateTime());
		return getTimeZone(frequency).contains(time);
	}

	public static List<String> getTimeZone(String frequency) {
		List<String> timeZone = new ArrayList<String>();
		BigDecimal bigFrequency = new BigDecimal(frequency);

		BigDecimal zone = new BigDecimal("1440").divide(bigFrequency);
		BigDecimal interval = new BigDecimal("24").divide(zone);

		BigDecimal i = new BigDecimal("0");
		do {
			String time = String.format("%02d", interval.multiply(i).toBigInteger());
			i = i.add(BigDecimal.ONE);
			timeZone.add(time);
		} while ((interval.multiply(i)).compareTo(new BigDecimal("24")) == -1);

		return timeZone;

	}
}
